import * as CookiesSave from '@/utils/auth'

const state = {
  currenpage: CookiesSave.getCurrenpage(),
  currensize: CookiesSave.getCurrensize(),
  currentotal: CookiesSave.getCurrentotal(),
  searchdata: CookiesSave.getSearchdata(),

  cacurrenpage: CookiesSave.getCacurrenpage(),
  cacurrensize: CookiesSave.getCacurrensize(),
  cacurrentotal: CookiesSave.getCacurrentotal(),
  casearchdata: CookiesSave.getCasearchdata()
}

const mutations = {
  SET_CURRENPAGE: (state, currenpage) => {
    state.currenpage = currenpage
  },
  SET_CURRENSIZE: (state, currensize) => {
    state.currensize = currensize
  },
  SET_CURRENTOTAL: (state, currentotal) => {
    state.currentotal = currentotal
  },
  SET_SEARCHDATA: (state, searchdata) => {
    state.searchdata = searchdata
  },
  SET_CACURRENPAGE: (state, cacurrenpage) => {
    state.cacurrenpage = cacurrenpage
  },
  SET_CACURRENSIZE: (state, cacurrensize) => {
    state.cacurrensize = cacurrensize
  },
  SET_CACURRENTOTAL: (state, cacurrentotal) => {
    state.cacurrentotal = cacurrentotal
  },
  SET_CASEARCHDATA: (state, casearchdata) => {
    state.casearchdata = casearchdata
  }
}

const actions = {
  searchData({ commit }, data) {
    commit('SET_CURRENPAGE', data.currenpage)
    CookiesSave.setCurrenpage(data.currenpage)
    commit('SET_CURRENSIZE', data.currensize)
    CookiesSave.setCurrensize(data.currensize)
    commit('SET_CURRENTOTAL', data.currentotal)
    CookiesSave.setCurrentotal(data.currentotal)
    commit('SET_SEARCHDATA', data.searchdata)
    CookiesSave.setSearchdata(data.searchdata)
  },
  caSearchData({ commit }, data) {
    commit('SET_CACURRENPAGE', data.cacurrenpage)
    CookiesSave.setCacurrenpage(data.cacurrenpage)
    commit('SET_CACURRENSIZE', data.cacurrensize)
    CookiesSave.setCacurrensize(data.cacurrensize)
    commit('SET_CACURRENTOTAL', data.cacurrentotal)
    CookiesSave.setCacurrentotal(data.cacurrentotal)
    commit('SET_CASEARCHDATA', data.casearchdata)
    CookiesSave.setCasearchdata(data.casearchdata)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
